//
//  ViewController.m
//  InduceTool
//
//  Created by 魏延龙 on 2020/8/3.
//  Copyright © 2020 魏延龙. All rights reserved.
//

#import "ViewController.h"
#import "ITWKWebViewController.h"
#import "ITVFLViewController.h"
#import "ITFileMD5ViewController.h"
#import "ITSlidScrollerViewController.h"
#import "SlidScrollViewController.h"
#import "ITStatusBarViewController.h"
#import "ITProgressViewController.h"
#import "ITDownLoadViewController.h"
#import "ITPageViewController.h"
#import "ITWifiViewController.h"
#import "ITWifiViewController.h"
#import "ITTCBDownloadViewController.h"
#import "ITOSSViewController.h"
#import "ITCNPAlertViewController.h"
#import "ITSCLAlertViewController.h"
#import "ITThemeViewController.h"
#import "ITSuperPlayerViewController.h"
#import "ITJSCallViewController.h"
#import "ITDownloadTaskViewController.h"
#import "ITDeviceOpsViewController.h"
#import "ITImageBrowserController.h"
#import "ITDicHookViewController.h"
#import "ITTouchIdViewController.h"
#import "ITMapTableViewController.h"
#import "ITRunTimeTestViewController.h"
#import "ITScanViewController.h"
#import "RHScanViewController.h"
#import "ITElementViewController.h"
#import "ITHTMLViewController.h"
#import "ITVisionViewController.h"
#import "ITDrawShapeViewController.h"
#import "ITSuperNavigationController.h"
#import "ITNaviViewController1.h"
#import "ITPickerViewController.h"
#import "ITLayoutSubViewVC.h"
#import "NestingViewController.h"
#import "YLCustomTabBarController.h"
#import "HitTestVC.h"
#import "ITGCDVC.h"
#import "MJPerson.h"


typedef void(^MJBlock)(void);
@interface ViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, strong) NSArray *dataSource;


@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.dataSource = @[
        @"webView URL 拦截",
        @"MD5",
        @"VFL 布局",
        @"下拉放大效果",
        @"scrollView 嵌套 tableView",
        
        @"修改状态栏 和导航栏颜色",
        @"渐变色 进度条",
        @"文件下载 - 1",
        @"文件下载 - 2",
        @"OSS 上传",
        
        @"pageViewController",
        @"wifi 信号强度",
        @"CNP 弹窗 好看",
        @"SCL 弹窗",
        @"主题切换",
        
        @"腾讯超级播放器",
        @"JS 交互",
        @"DownloadTask 下载",
        @"设备内部操作",
        @"图片浏览器",
        
        @"不可变字典初始化防崩溃",
        @"touchID 登录",
        @"NSMapTable",
        @"RunTime 测试",
        @"扫一扫",
        
        @"另一个扫一扫",
        @"js 操作",
        @"显示html标签",
        @"vision 识别",
        @"画图",
        
        @"导航控制器",
        @"pickerView",
        @"layoutViews",
        @"cell 嵌套 tableView",
        @"自定义tabbarController",
        
        @"响应者",
        @"GCD",
        @"崩溃",
    ];
    [self.view addSubview:self.tableView];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(obsAction:) name:nil object:@1];
    [[NSNotificationCenter defaultCenter] addObserverForName:nil object:@1 queue:nil usingBlock:^(NSNotification * _Nonnull note) {
        NSLog(@"obsAction queue");
    }];
    
    
    NSObject *object = [[NSObject alloc] init];
    id __weak obj1 = object;
    id __weak obj2 = object;
    
    NSLog(@":::::::%p--%p",&obj1, &obj2);
    
}
-(void)obsAction:(NSNotification *)noti {
    NSLog(@"obsAction");
   
    
    
    
    //block
    static int age = 10;
    MJBlock block = ^ {
        age = 20;
        NSLog(@"block");
    };


    MJPerson *person = [[MJPerson alloc] init];
    person.age = 189;
    NSLog(@"---- %p,%p",person, person.age);
    
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    NSString *aa = INDUCE_VALUE;

    //获取 Version  版本号
    NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
    NSLog(@"version %@ aa %@", version, aa);

    // build setting 中搜索 Preprocessor
    #if TARGET_VERSION == 1
    NSLog(@" 1 version %@ aa %@", version, aa);
    #elif TARGET_VERSION == 2
    NSLog(@" 2 version %@ aa %@", version, aa);
    #elif TARGET_VERSION == 3
    NSLog(@" 3 version %@ aa %@", version, aa);
    #elif TARGET_VERSION == 4
    NSLog(@" 4 version %@ aa %@", version, aa);
    #endif
}

- (void)viewWillLayoutSubviews {
    self.tableView.frame = self.view.bounds;
}

- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] init];
        [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:NSStringFromClass([UITableViewCell class])];
        _tableView.frame = self.view.bounds;
        _tableView.delegate = self;
        _tableView.dataSource = self;
    }
    return _tableView;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([UITableViewCell class]) forIndexPath:indexPath];
    cell.textLabel.text = self.dataSource[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.row == 0) {
        // webView URL 拦截
        [self.navigationController pushViewController:[ITWKWebViewController new] animated:YES];
    } else if (indexPath.row == 1) {
        // MD5
        [self.navigationController pushViewController:[ITFileMD5ViewController new] animated:YES];
    } else if (indexPath.row == 2) {
        // VFL 布局
        [self.navigationController pushViewController:[ITVFLViewController new] animated:YES];
    } else if (indexPath.row == 3) {
        // 下拉放大效果
        [self.navigationController pushViewController:[ITSlidScrollerViewController new] animated:YES];
    } else if (indexPath.row == 4) {
        // scrollView 嵌套 tableView
        [self.navigationController pushViewController:[SlidScrollViewController new] animated:YES];
    } else if (indexPath.row == 5) {
        // 修改状态栏 和导航栏颜色
        [self.navigationController pushViewController:[ITStatusBarViewController new] animated:YES];
    } else if (indexPath.row == 6) {
        // 渐变色 进度条
        [self.navigationController pushViewController:[ITProgressViewController new] animated:YES];
    } else if (indexPath.row == 7) {
        // 文件下载 - 1
        [self.navigationController pushViewController:[ITDownLoadViewController new] animated:YES];
    } else if (indexPath.row == 8) {
        // 文件下载 - 2
        [self.navigationController pushViewController:[ITTCBDownloadViewController new] animated:YES];
    } else if (indexPath.row == 9) {
        // OSS 上传
        [self.navigationController pushViewController:[ITOSSViewController new] animated:YES];
    } else if (indexPath.row == 10) {
        // pageViewController
        [self.navigationController pushViewController:[ITPageViewController new] animated:YES];
    } else if (indexPath.row == 11) {
        // wifi 信号强度
        [self.navigationController pushViewController:[ITWifiViewController new] animated:YES];
    } else if (indexPath.row == 12) {
        // CNP 弹框
        [self.navigationController pushViewController:[ITCNPAlertViewController new] animated:YES];
    } else if (indexPath.row == 13) {
        // SCL 弹窗
        [self.navigationController pushViewController:[ITSCLAlertViewController new] animated:YES];
    } else if (indexPath.row == 14) {
        // 主题切换
        [self.navigationController pushViewController:[ITThemeViewController new] animated:YES];
    } else if (indexPath.row == 15) {
        // 腾讯超级播放器
        [self.navigationController pushViewController:[ITSuperPlayerViewController new] animated:YES];
    } else if (indexPath.row == 16) {
        // JS 交互
        [self.navigationController pushViewController:[ITJSCallViewController new] animated:YES];
    } else if (indexPath.row == 17) {
        // DownloadTask 下载
        [self.navigationController pushViewController:[ITDownloadTaskViewController new] animated:YES];
    } else if (indexPath.row == 18) {
        // DownloadTask 下载
        UIStoryboard *sb = [UIStoryboard storyboardWithName:@"DeviceOption" bundle:nil];
        ITDeviceOpsViewController *opvc = [sb instantiateViewControllerWithIdentifier:@"ITDeviceOpsViewController"];
        [self.navigationController pushViewController:opvc animated:YES];
    } else if (indexPath.row == 19) {
        // 图片浏览器
        [self.navigationController pushViewController:[ITImageBrowserController new] animated:YES];
    } else if (indexPath.row == 20) {
        // 不可变字典初始化防崩溃
        [self.navigationController pushViewController:[ITDicHookViewController new] animated:YES];
    } else if (indexPath.row == 21) {
        [self.navigationController pushViewController:[ITTouchIdViewController new] animated:YES];
    } else if (indexPath.row == 22) {
        [self.navigationController pushViewController:[ITMapTableViewController new] animated:YES];
    } else if (indexPath.row == 23) {
        //@"RunTime 测试",
        [self.navigationController pushViewController:[ITRunTimeTestViewController new] animated:YES];
    } else if (indexPath.row == 24) {
        //@"扫一扫",
        [self.navigationController pushViewController:[ITScanViewController new] animated:YES];
    } else if (indexPath.row == 25) {
        //@"另一个扫一扫",
        [self.navigationController pushViewController:[RHScanViewController new] animated:YES];
    } else if (indexPath.row == 26) {
        //@"js 操作",
        [self.navigationController pushViewController:[ITElementViewController new] animated:YES];
    } else if (indexPath.row == 27) {
        //@"显示标签文本",
        [self.navigationController pushViewController:[ITHTMLViewController new] animated:YES];
    } else if (indexPath.row == 28) {
        //@"vision 识别",
        [self.navigationController pushViewController:[ITVisionViewController new] animated:YES];
    } else if (indexPath.row == 29) {
        //@"画图",
        [self.navigationController pushViewController:[ITDrawShapeViewController new] animated:YES];
    } else if (indexPath.row == 30) {
        //@"导航控制器",
        ITSuperNavigationController *baseControl = [[ITSuperNavigationController alloc] initWithRootViewController:[ITNaviViewController1 new]];
        [UIApplication sharedApplication].keyWindow.rootViewController = baseControl;
    } else if (indexPath.row == 31) {
        //@"pickerView",
        [self.navigationController pushViewController:[ITPickerViewController new] animated:YES];
    } else if (indexPath.row == 32) {
        [self.navigationController pushViewController:[ITLayoutSubViewVC new] animated:YES];
    } else if (indexPath.row == 33) {
        // cell 嵌套tableView
        [self.navigationController pushViewController:[NestingViewController new] animated:YES];
    } else if (indexPath.row == 34) {
        //@"自定义tabbarController",
        [self.navigationController pushViewController:[YLCustomTabBarController new] animated:YES];
    } else if (indexPath.row == 35) {
        // "响应者"
        [self.navigationController pushViewController:[HitTestVC new] animated:YES];
    } else if (indexPath.row == 36) {
        // GCD
        [self.navigationController pushViewController:[ITGCDVC new] animated:YES];
    } else if (indexPath.row == 37) {
        // 崩溃
//        NSArray *arr = @[@"qww"];
//        NSLog(@"aaa : %@",arr[1]);
        
        void *pc = malloc(1024);
        free(pc);
        free(pc);  //打开注释会导致错误
        printf("free ok!\n");
    }
    
    
}

@end
